home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5959 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.eden.com!usenet
  2. From: Shane Sadler <nexus@eden.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Do you have ever pass structures?
  5. Date: Wed, 21 Feb 1996 20:58:01 -0700
  6. Organization: Eden Matrix Services
  7. Message-ID: <312BE9C9.67A2284E@eden.com>
  8. References: <4ge8mi$qjm@srvr1.engin.umich.edu>
  9. NNTP-Posting-Host: net-1-215.austin.eden.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.8 i586)
  14.  
  15. HASDI RODZMANN HASHIM wrote:
  16.  
  17. > So is there any REAL advantage is passing an entire structure? Do people
  18. > ever do it? I've some people's source code and almost always, they
  19. > pass pointers to structures instead of the structure itself. In a way,
  20. > passing a pointer to an array instead of the array itself might be
  21. > feature not a bug in C. :)
  22.  
  23. Hasdi,
  24.  
  25. As you know passing an entire structure to a function pushes that
  26. structure onto the stack. By passing pointers, you avoid that sort of
  27. overhead and your code is more efficient. When I'm writing what Mr.
  28. Collins would call "disposable programs," I might just declare my
  29. structures globally just out of laziness and expediency, but I can't
  30. think of a case in which I would pass the whole structure. So my answer
  31. would be "no". Of course, someone else may have experience with passing
  32. very small structures (one or two elements). There might be some
  33. advantage in this, but a "REAL" advantage? I doubt it. Depends on what
  34. you mean by "REAL," I guess...
  35.  
  36. -- Shane
  37. ===================================================================
  38. S. M. Sadler
  39. e-mail: nexus@eden.com
  40. Web: http://www.eden.com/~nexus
  41.